package com.mworld.galaxy.bull.util;

import javax.servlet.http.HttpServletRequest;

import com.mworld.galaxy.bull.entity.product.Shop;
import com.mworld.galaxy.bull.service.product.ShopService;

public class ShopUtil {
    public static String getShopNameOrId(HttpServletRequest request) {
        boolean testRequest = request.getParameter("testShop") != null;
        String server = request.getServerName();
        int index = server.indexOf(".51qianlima.cn");
        if (index > 0) {
            return server.substring(0, index);
        }
        if (testRequest) {
            return ShopService.DEFAULT_SHOP_ID + "";
        }
        return null;
    }

    public static Shop getShopByDomainNameOrId(ShopService shopService, String domainNameOrId) {
        Shop shop = shopService.getShopByDomainName(domainNameOrId);
        if (shop == null) {
            shop = shopService.getShop(domainNameOrId);
        }
        return shop;
    }
}
